<div class="header02_right">
  <div class="header_search_01"> 
      <div id="txtcommit" class="base_color"> Các khách sạn Việt Nam và Quốc tế</div> 
      <div id="quick_search" onclick="displayButton(1)">
          <form action="<?php echo site_url('searchKhachSan/search_Hotel') ?>" id="form_search_name" name="form_search_name" method="post" >
              <input type="text" size="50" maxlength="80" id="searchname" name="searchname" value="Nhập tên thành phố hoặc tên khách sạn..." onfocus='clearText(this)' onblur='clearText(this)' class="B_input" />
              <input type="hidden" id="tp" name="tp" value=""/>
              <input type="hidden" id="qg" name="qg" value=""/>
              <input type="hidden" id="kv" name="kv" value=""/>    
          <div id="search_button_1" class="button1" style="display:inline; width:65px; margin-left:5px; padding-left:5px; padding-right:5px; padding-top:5px; padding-bottom:5px;">Tìm kiếm</div>
          </div>
      </div>
      <div class="header_search_02">
          <div id="destination_search" onclick="displayButton(2)">
              <select id='id_des_country' class="option_search" name="id_des_country" onchange="getCityByCountry();" style="width:120px">
                  <option value="" selected="selected">Quốc gia</option>
                  <?php 
                      foreach ($country as $row) 
                      { 
                          echo "<option value='$row->QuocGia'>$row->QuocGia</option>";
                      } 
                  ?>
              </select>

              <select id='id_des_city' class="option_search" name="id_des_city" onchange="getRegionByCity(); displayButton(2);" style="width:120px;">
                  <option value="" selected="selected">Thành phố</option>
              </select>

              <select id='id_des_region' class="option_search" name="id_des_region" style="width:120px">
                  <option value="" selected="selected">Khu vực</option>
              </select>
              
              <div id="search_button_2" class="button1" style="display:none; width:65px; padding-left:5px; padding-right:5px; padding-top:5px; padding-bottom:5px;">Tìm kiếm</div>
          </div>
      </div>
      <div class="base_color"><font size="+1"><b> Ngày nhận phòng: </b></font></div>
          <input id="date" type="text" class="date_search" value='<?php echo date('d/m/Y'); ?>' />
          <input type='hidden' name='date' id='actualDate_tim' value='<?php echo date('Y-m-d', strtotime("now")); ?>' />
          </form>
  </div>
  
<style>
  .ui-autocomplete-category 
  {
	  font-family: Verdana, Geneva, sans-serif;
	  font-weight: bold;
	  padding: .2em .4em;
	  color: #06F;
	  font-size: 14px;
  }
</style>        
   
<script type="text/javascript">
	jQuery.widget( "custom.catcomplete", jQuery.ui.autocomplete, {
		_renderMenu: function( ul, items ) {
			var that = this;
				currentCategory = "";
			jQuery.each( items, function( index, item ) {
				if ( item.category != currentCategory ) {
					ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
					currentCategory = item.category;
				}
				that._renderItemData( ul, item );
			});
		}
	});	
											  
	jQuery(function()
	{	  
		jQuery( "#searchname" ).catcomplete(
		{							  
			source: function (request, response)
			{
				jQuery.ajax(
				{
					url: "index.php/khachsan/LayThanhPho_TenKhachSan_ajax",
					type: 'POST',
					dataType: "json",
					data: 
					{
						style: "full",
						maxRows: 12,
						name_startsWith: request.term
					},					
					success: function(msg)
					{
						response(jQuery.map(msg, function(item)
						{
							return {label: item.label, category: item.category};
						}));
					}
				});
			},
			minLength: 2
		});
		
	   jQuery( "#date" ).datepicker(
	   {
			changeMonth: true,
			changeYear: true,
			altField: '#actualDate_tim',
			altFormat: 'yy-mm-dd',
			dateFormat: 'dd/mm/yy'
		});	   							  
	});
	
	function clearText(field)
	{
		if (field.defaultValue == field.value) field.value = '';
		else if (field.value == '') field.value = field.defaultValue;
	}
	
	function displayButton(btn)
	{
		btn1 = document.getElementById("search_button_1");
		btn2 = document.getElementById("search_button_2");
		
		if(btn == 1)
		{
			btn1.style.display = "inline";
			btn2.style.display = "none";
		}
		else 
		{	
			btn2.style.display = "inline";
			btn1.style.display = "none";
			document.getElementById("searchname").value = "Nhập tên thành phố hoặc tên khách sạn...";												
		}
	}
	
	jQuery("#id_des_country").change(function()
	{
		var form_data = 
		{
			choice: '1', 
			quocgia:jQuery('#id_des_country').val()
		};
		jQuery.ajax(
		{
			url: "<?php echo site_url('searchKhachSan/getCityByCountry'); ?>",
			type: "POST",
			data: form_data,
			dataType: 'html',
			success: function(mgs)
			{
				jQuery('#destination_search').html(mgs);
				jQuery('#qg').val(jQuery('#id_des_country').val());
			}
		});
	 });
  
	 jQuery("#id_des_city").change(function()
	 {				
		var form_data = 
		{
			choice: '2',
			quocgia:jQuery('#id_des_country').val(),
			thanhpho:jQuery('#id_des_city').val()
		};
		jQuery.ajax(
		{
			url: "<?php echo site_url('searchKhachSan/getRegionByCity'); ?>",
			type:"POST",
			data: form_data,
			dataType: 'html',
			success: function(mgs)
			{
				jQuery('#destination_search').html(mgs);
				jQuery('#tp').val(jQuery('#id_des_city').val());
			}
		});
	});
	
	jQuery("#id_des_region").change(function()
	{
		jQuery('#kv').val(jQuery('#id_des_region').val());
	});
  											
	jQuery("#search_button_1").click(function()
	{
		if(jQuery('#searchname').val()=='Nhập tên thành phố hoặc tên khách sạn...')
		{
			alert("Xin vui lòng nhập tên khách sạn (hoặc thành phố)!");
			return;
		}
		jQuery('#form_search_name').submit();
	});
	
	jQuery("#search_button_2").click(function()
	{
		if(jQuery('#id_des_country').val()=="")
		{
			alert("Xin vui lòng lựa chọn các tiêu chí có sẵn!");
			return;
		}
		if(jQuery('#id_des_city').val()=="")
		{
			alert("Xin vui lòng chọn thành phố!");
			return;
		}
		jQuery('#form_search_name').submit();
	});							
</script>


